//
//  XMLGenerator.h
//  Schedule
//
//  Created by Julius Canute on 2/16/12.
//  Copyright 2012 ABB. All rights reserved.
//

#ifndef Schedule_XMLGenerator_h
#define Schedule_XMLGenerator_h
#include <iostream>
#include <xercesc/util/PlatformUtils.hpp>
#include <xercesc/dom/DOM.hpp>
#include <xercesc/util/XMLString.hpp>
#include <xercesc/framework/XMLFormatter.hpp>
#include <xercesc/framework/StdOutFormatTarget.hpp>
#include <xercesc/framework/LocalFileFormatTarget.hpp>
#define XMLSTRLEN 100

using namespace xercesc;

using namespace std;

class XMLGenerator {
    
private:
    DOMImplementation *impl;
    //DOMLSSerializer *theSerializer;
    DOMDocument *doc;
    DOMElement *root;
    XMLCh tempStr[XMLSTRLEN];
public:
    XMLGenerator(){
        XMLPlatformUtils::Initialize();
        XMLString::transcode("XML", tempStr, (XMLSTRLEN - 1));
        impl = DOMImplementationRegistry::getDOMImplementation(tempStr);
        XMLString::transcode("Schedule", tempStr, (XMLSTRLEN - 1));
        doc = impl->createDocument(0, tempStr, 0);
        root = doc->getDocumentElement();
        //theSerializer = ((DOMImplementationLS*)impl)->createLSSerializer();
    }
    //Getters
    DOMElement* getRoot()
    {
        return root;
    }
    //Add element relative to the parent 
    DOMElement* addElement(DOMElement *parent,const char *tagName,const char *tagText,bool flag,const char *attrib = NULL, const char *value =NULL );
    //Dump XML to console
    int SerializeToConsole();
    //Dump XML to a given file name
    int SerializeToFile(const char *name);
    
    ~XMLGenerator(){
        //theSerializer->release();
        doc->release();
        XMLPlatformUtils::Terminate();
    }
};


#endif
